function regionalPLIAnalysisMain(inDir,filter,outDir)

%filter='*alpha*';
files=dir(fullfile(inDir,filter));
nAreas=16;
fileNames=cell(length(files),1);
areas='';
areaLabels='';
mAnova=[];
for i=1:length(files)
    fileNames{i}=files(i).name;
    info=whos('-file',fullfile(inDir,fileNames{i}));    
    varName=info.name;
    load(fullfile(inDir,fileNames{i}),varName);
    nSubjs=size(eval(varName),1);
    regional.intraArea=zeros(nSubjs,nAreas)
    regional.interArea=zeros(nSubjs,(nAreas*(nAreas-1))/2);
     for j=1:nSubjs
        m=squeeze(eval(strcat(varName,'(j,:,:)')));
        [areas,areaLabels,regional.intraArea(j,:),regional.interArea(j,:)]=regionalAnalysis(m);
     end
     [cond,rem]=strtok(fileNames{i},'.');
     save(fullfile(outDir,strcat(cond,'_regional')),'regional','areas','areaLabels');   
     mAnova=[mAnova regional.intraArea];
end
[band,rem]=strtok(fileNames{1},'_');
save(fullfile(outDir,strcat(band,'_names')),'fileNames');   
fileout=strcat(band,'_rmAnova.txt');
levels=[4 2 8];
varNames={'Condition','Hemisphere','Area'};

diary(fullfile(outDir,fileout))
O = teg_repeated_measures_ANOVA(mAnova, levels, varNames);
diary off;





